const express = require('express');

const loginService = require('../service/login');

const router = express.Router();

// 登录卡密接口
// 待办：token时间忘记限制 数据库每登录一次需要次数+1
router.post('/cardkey-login', async function (req, res, next) {
    // 获取的是主卡密
    let cardkey = req.headers.authorization;
    if (!cardkey) {
        res.status(401).json({ code: 401, msg: "卡密不允许为空", data: null });
        return;
    }
    // 调用业务层进行验证，颁发一个 jwt 给用户
    loginService.cardkeyLogin(cardkey, req.time).then(result => {
        res.status(result.code).json(result);
    }).catch(err => {
        result = { code: 500, msg: "服务器错误", data: null };
    });
});


module.exports = router;